import { mapGetters, mapState } from "vuex";

export default {
	data: function () {
		return {
			REDIRECT_URL :"http://www.qzzhuoen.com/#/login",//回跳地址
			CORPID : "ww9643385df2ca2627",//企业微信id
		}
	},
	computed:{
		...mapState("userWork",['userId','externalUserId','token','userInfo']),
		...mapGetters("userWork",['isLoginUser','isLoginExternalUser'])
	},
	methods:{
		
		//企业微信跳转用的
		getRedirectUrlWorkder(){
			let REDIRECT_URI = this.REDIRECT_URL  //跳转回前端的url地址
			REDIRECT_URI = encodeURIComponent(REDIRECT_URI)
			console.log('要回跳的地址',REDIRECT_URI)
			let url = this.splicingCodeUrlOfWxwork(REDIRECT_URI)
			// let url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+this.CORPID+"&redirect_uri="+REDIRECT_URI+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
			return url
		},
		
		
		// 外部客户要跳回的,主要是加了额外的参数
		// 参数使用localstorage来储存，就用不着这个参数方式的了
		getRedirectUrlExternal(couponId){
			let REDIRECT_URI = this.this.REDIRECT_URL + "?couponId="+couponId //跳转回前端的url地址
			REDIRECT_URI = encodeURIComponent(REDIRECT_URI)
			console.log('要回跳的地址',REDIRECT_URI)
			let url = this.splicingCodeUrlOfWxwork(REDIRECT_URI)
			// let url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+this.CORPID+"&redirect_uri="+REDIRECT_URI+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
			return url
		},
		
		
		//拼接获取code的跳转url（企业微信的）
		splicingCodeUrlOfWxwork (redirectUrl){
			return "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+this.CORPID+"&redirect_uri="+redirectUrl+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
		},
		
		//清理缓存
		clearCache(){
			localStorage.removeItem("couponId")
			localStorage.removeItem("userId")
			localStorage.removeItem("openId")
			Swal.fire({
			 // position:'top',
			 html: '清理缓存成功',
			 type: "success",
			 showConfirmButton: false,
			 timer:1000,
			 backdrop:true,//遮罩
			 allowOutsideClick: false,//允许外部点击关闭
			 // onBeforeOpen: () => { Swal.showLoading() },
			 onAfterClose: () => {console.log("关闭")}
			 });
		}
	}
}
